package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.OmcHuaLongRosterItemMapper;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.domain.OmcHuaLongRosterItem;
import com.csun.cmny.provider.model.dto.hualong.HuaLongRosterShiftDto;
import com.csun.cmny.provider.service.OmcHuaLongRosterItemService;
import com.csun.cmny.util.PublicUtil;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2020-10-29 14:27
 * @Description:
 */
@Service
@Transactional
public class OmcHuaLongRosterItemServiceImpl extends BaseService<OmcHuaLongRosterItem>
        implements OmcHuaLongRosterItemService {

    @Resource
    private OmcHuaLongRosterItemMapper omcHuaLongRosterItemMapper;

    /**
     * 修改排班项
     *
     * @param huaLongRosterShiftDto the hua long roster shift dto
     * @param loginAuthDto          the login auth dto
     *
     * @return the int.
     */
    @Override
    public Integer changeById(HuaLongRosterShiftDto huaLongRosterShiftDto, LoginAuthDto loginAuthDto) {

        Long id = huaLongRosterShiftDto.getId();
        if (PublicUtil.isEmpty(id)) {
            throw new OmcBizException(ErrorCodeEnum.OMC10090003);
        }

        OmcHuaLongRosterItem omcHuaLongRosterItem = omcHuaLongRosterItemMapper.selectByPrimaryKey(id);
        if (PublicUtil.isEmpty(omcHuaLongRosterItem)) {
            throw new OmcBizException(ErrorCodeEnum.OMC10090004);
        }

        // 是否强休
        if (PublicUtil.isNotEmpty(huaLongRosterShiftDto.getIsStrong())) {
            omcHuaLongRosterItem.setIsStrong(huaLongRosterShiftDto.getIsStrong());
        }

        // 班次
        if (PublicUtil.isNotEmpty(huaLongRosterShiftDto.getShift())) {
            omcHuaLongRosterItem.setShift(huaLongRosterShiftDto.getShift());
        }

        // 日期
        if (PublicUtil.isNotEmpty(huaLongRosterShiftDto.getDay())) {
            omcHuaLongRosterItem.setDay(huaLongRosterShiftDto.getDay());
        }

        // 星期
        if (PublicUtil.isNotEmpty(huaLongRosterShiftDto.getWeek())) {
            omcHuaLongRosterItem.setWeek(huaLongRosterShiftDto.getWeek());
        }

        return omcHuaLongRosterItemMapper.updateByPrimaryKeySelective(omcHuaLongRosterItem);
    }
}
